<template>
  <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
      >
      <!-- {{loading}} -->
      <listItem v-for="(item,index) in resultlist" :key="index" :articleData="item" />
      <!-- <van-cell v-for="(item,index) in resultlist" :key="index" :title="item.title" /> -->
  </van-list>
</template>

<script>
import listItem from '@/components/ListItem.vue'
import {getsearch} from '@/api/search'
export default {
  components: {listItem},
  props: {
    querydata:{
      require:true,
      type:String
    }
  },
  data() {
    return {
      finished: false,
      list: [],
      loading:false,
      resultlist:[],
      param:{
        page:1,
        pre_page:10,
        q:''
      }
    }
    
  },
  methods: {
    async onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      if(this.param.page>11){return}
      try{
        console.log(this.querydata)
        this.param.q=this.querydata
        const {data} =await getsearch(this.param)
        if(data){
          this.loading=false;
          console.log(this.loading)
        }
        this.resultlist.push(...data.data.results)
        if(!data.data.results.length){
          console.log('finish')
          this.finished=true;
          return
        }else{
          this.param.page+=1
        }
        
      }catch(err){
        console.log('获取数据失败...',err)
      }
      
    },
    
  },
  watch: {},
  computed: {

  },
 
  created() {
    this.resultlist=[]
  },
  mounted() {

  }
};
</script>
<style lang="less" scoped>
</style>